package com.informationsystem.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Repository;

import com.informationsystem.dao.SystemuserDao;
import com.informationsystem.model.Systemuser;

public class UserDetailServiceImpl implements  UserDetailsService {

	private SystemuserDao systemuserDao;
	
	@Override
	public UserDetails loadUserByUsername(String username)
			throws UsernameNotFoundException {
		
		Systemuser user = getSystemuserDao().getAll().get(0);
		if(user==null)
			return null;
	    List<GrantedAuthority> authsList = new ArrayList<GrantedAuthority>();
	    
	    org.springframework.security.core.userdetails.User userdetail = new org.springframework.security.core.userdetails.User(  
	    		user.getUsername(), user.getPassword(), true, true, true, true, authsList);  
	    return userdetail;
	}

	public SystemuserDao getSystemuserDao() {
		return systemuserDao;
	}

	public void setSystemuserDao(SystemuserDao systemuserDao) {
		this.systemuserDao = systemuserDao;
	}

}
